package com.yuandian.management.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfComponentIp;
import com.yuandian.api.management.po.ConfComponentIpParam;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfComponentIpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 组件IP配置表-Controller
 * @author zfsn
 * @date 2023-3-16
 */
@Api(tags = "it组件IP配置表功能接口")
@RestController
@RequestMapping("/componentIp")
public class ConfComponentIpController {

	@Autowired
	private ConfComponentIpService confComponentIpService;

	/**
	 * 通过主键查询数据
	 *
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfComponentIp>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confComponentIpService.listByIds(idList));
	}

	/**
	 * 通过主键查询数据
	 *
	 * @param confComponentIpParam 请求对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过网端id查询数据，支持批量查询")
	@PostMapping("queryBySegmentIds")
	public R<List<ConfComponentIp>> queryBySegmentIds(@RequestBody ConfComponentIpParam confComponentIpParam) {
		QueryWrapper<ConfComponentIp> queryWrapper = new QueryWrapper<>();
		queryWrapper.in("segment_id", confComponentIpParam.getSegmentIds());
		queryWrapper.eq("system_id", confComponentIpParam.getSystemId());
		return R.ok(confComponentIpService.list(queryWrapper));
	}

	/**
	 * 分页查询
	 *
	 * @param
	 * @param confComponentIp 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = false, dataType = "Integer"),
			@ApiImplicitParam(name = "segmentId", value = "所属网段", paramType = "body", required = false, dataType = "Integer"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataType = "Integer"),
	})
	public R<Page<ConfComponentIp>> listPage(@ApiIgnore @RequestBody ConfComponentIp confComponentIp) {
		return R.ok(confComponentIpService.listPage(confComponentIp));
	}

	/**
	 * 新增数据
	 *
	 * @param confComponentIp 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增组件IP配置表数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "segmentId", value = "所属网段", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "port", value = "端口", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ip", value = "ip", paramType = "body", required = true, dataType = "String"),
	})
	public R<String> save(@RequestBody @ApiIgnore ConfComponentIp confComponentIp) {
		return confComponentIpService.saveConfig(confComponentIp);
	}

	/**
	 * 通过主键更新数据
	 *
	 * @param confComponentIp 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新组件IP配置表数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = false, dataType = "Integer"),
			@ApiImplicitParam(name = "segmentId", value = "所属网段", paramType = "body", required = false, dataType = "Integer"),
			@ApiImplicitParam(name = "port", value = "端口", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ip", value = "ip", paramType = "body", required = true, dataType = "String"),
	})
	public R<Boolean> updateById(@RequestBody @ApiIgnore ConfComponentIp confComponentIp) {
		return R.ok(confComponentIpService.updateById(confComponentIp));
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除组件IP配置表数据")
	@DeleteMapping("delete/{ids}")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> ids) {
		return R.ok(confComponentIpService.removeByIds(ids));
	}
}
